package com.lams.service.comp.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.lams.jdbc.IBaseDAO;
import com.lams.jdbc.QueryUtils;
import com.lams.service.BaseFacade;
import com.lams.service.comp.IAutoCompleteFacade;

public class AutoCompleteFacade extends BaseFacade implements IAutoCompleteFacade {
	@Override
	public Map queryData(Map params) {
		String sqlCode = (String)params.get("sqlCode");
		String sql = QueryUtils.getSqlBySqlCode(sqlCode, params);
		int limit = 10;
		int start = 0;
		if(params.containsKey("limit") || params.get("limit")!=null){
			limit = Integer.parseInt(String.valueOf(params.get("limit")));
		}
		if(params.containsKey("start") || params.get("start")!=null){
			start = Integer.parseInt(String.valueOf(params.get("start")));
		}
		List data = QueryUtils.executeQuery(start, limit, sql);
		int totalCount = QueryUtils.getTotalCount(sql);
		Map result = new HashMap();
		result.put("data", data);
		result.put("totalCount", totalCount);
		return result;
	}

}
